const fs = require('fs')
const path = require('path')
const xlsx = require('node-xlsx')

let dirs = ['蒙德', '璃月', '稻妻']
let sheets = []
for (let i = 0; i < dirs.length; i++) {
    const dir = dirs[i];
    let files = fs.readdirSync(dir)
    for (let j = 0; j < files.length; j++) {
        const file = files[j];
        if (file == 'template.json') {
            continue
        }
        let data = JSON.parse(fs.readFileSync(path.join(dir, file)).toString())
        let keys = ['角色语音', '战斗语音']
        let sheet = { name: file.replace('.json', ''), data: [] }
        for (const key in data[keys[0]]) {
            if (Object.hasOwnProperty.call(data[keys[0]], key)) {
                sheet['data'].push([key, data[keys[0]][key]])
            }
        }
        for (const key in data[keys[1]]) {
            if (Object.hasOwnProperty.call(data[keys[1]], key)) {
                sheet['data'].push([key, data[keys[1]][key]])
            }
        }
        sheets.push(sheet)
    }
}

let buffer = xlsx.build(sheets)

fs.writeFileSync('summary.xlsx', buffer)